class Admin::OrdersController < Admin::AdminController
  filter_resource_access

  add_crumb("Správa objednávek", :only => :index) {}
  add_crumb("Správa objednávek", :admin_orders_path, :except => :index)
  add_crumb("Editace objednávky", :only => [:edit, :update]) {}

  def index
    @search = Order.order_completed.search(params[:search])
    @orders = @search.page(params[:page])

    @orders_by_day = Order.where(["date(completed_at) BETWEEN ? AND ?", 1.month.ago.beginning_of_day, Date.today.end_of_day]).
                          order(:completed_at).
                          group("DATE(completed_at)").
                          select("completed_at, count(*) as quantity, sum(total) as total")
  end

  def edit
  end

  def update
    if @order.update_attributes(params[:order])
      redirect_to edit_admin_order_path(@order), :notice => "Objednávka byla úspěšně upravena."
    else
      render :action => :edit
    end
  end
end
